/*
 * @filename ErrorCode.java
 * 
 * @author barry
 * 
 * @version 0.0.1
 * 
 * @date 2020年1月19日
 */
package com.bnzj.core.rest;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @author barry
 * @date 2020-01-19
 */
@Getter
@RequiredArgsConstructor
public class ResultCode {
    //1000～1999 区间表示参数错误
    //2000～2999 区间表示用户错误
    //3000～3999 区间表示接口异常
    // 5000 试题已存在
    
    public static final int SUCCEED = 1;
    
    public static final int FAILURE = 0;
    
    public static final int ACCESS_DENIED = 10403;//无访问权限
    
    public static final int UNKNOWN = 10500;//未知错误
    
    public static final int NOT_FOUND = 10404;//未知请求
    
    public static final int BAD_REQUEST = 10400;//错误请求
    
    public static final int RESOURCE_NOT_EXIST = 11010;//资源不存在
    
    public static final int NOT_ALLOWED_TO_DELETE = 11011;//不允许删除


    private final int code;

    private final String msg;
    
    private static final Map<String, ResultCode> errorCodeMap = new ConcurrentHashMap<String, ResultCode>();

    public static ResultCode getResultCode(int code) {
        return errorCodeMap.get(Integer.toString(code));
    }

    public static void setResultCode(int code, ResultCode msg) {
        errorCodeMap.put(Integer.toString(code), msg);
    }
    
    static {
        setResultCode(SUCCEED, new ResultCode(SUCCEED, "处理成功"));
        setResultCode(FAILURE, new ResultCode(FAILURE, "请求失败"));
        setResultCode(UNKNOWN, new ResultCode(UNKNOWN, "未知错误"));
        setResultCode(NOT_FOUND, new ResultCode(NOT_FOUND, "找不到你需要的内容"));
        setResultCode(BAD_REQUEST, new ResultCode(BAD_REQUEST, "错误的请求"));
        setResultCode(ACCESS_DENIED, new ResultCode(ACCESS_DENIED, "无访问权限"));
        setResultCode(RESOURCE_NOT_EXIST, new ResultCode(RESOURCE_NOT_EXIST, "资源不存在"));
        setResultCode(NOT_ALLOWED_TO_DELETE, new ResultCode(NOT_ALLOWED_TO_DELETE, "不允许删除"));
        
    }
}
